#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    string addBinary(string a, string b) {
        int s1 = a.size() - 1, s2 = b.size() - 1;
        int carry = 0;
        string ret = "";
        while (s1 >= 0 || s2 >= 0 || carry)
        {
            if (s1 >= 0)
                carry += a[s1--] - '0';
            if (s2 >= 0)
                carry += b[s2--] - '0';
            ret += to_string(carry % 2);
            carry /= 2;
        }
        reverse(ret.begin(), ret.end());
        return ret;
    }
};